/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package network.packets;

import utils.StringUtils;
import utils.Utils;
/**
 *
 * @author Kvest
 */
public class LoginResponce extends Packet
{
    public static final String ANSWER_OK = "AllIsInOrder";
    
    private int srvID;
    private int peopleID;
    private String answer;
    private byte[] GUID;
    private int packetNumber;

    public LoginResponce(byte[] data)
    {
        super(LOGIN_RESPONCE);
        srvID = -1;
        peopleID = -1;
        answer = "";
        GUID = new byte[16];
        packetNumber = -1;

        parse(data);
    }

    protected void parse(byte[] data)
    {
        int offset = 0;

        //Пропускаем название пакета
        byte[] buffer4 = new byte[4];
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length + Utils.byteToInt(buffer4);

        //SrvID
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        srvID = Utils.byteToInt(buffer4);

        //PeopleID
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        peopleID = Utils.byteToInt(buffer4);
        
        //Answer
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        int strSize = Utils.byteToInt(buffer4);
        byte[] buffer = new byte[strSize];
        System.arraycopy(data, offset, buffer, 0, buffer.length);
        offset += buffer.length;
        answer = StringUtils.bytesToStr(buffer);

        //GUID
        System.arraycopy(data, offset, GUID, 0, GUID.length);
        offset += GUID.length;

        //PacketNumber
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        packetNumber = Utils.byteToInt(buffer4);

        buffer4 = null;
        buffer = null;
    }

    public int getSrvID()
    {
        return srvID;
    }

    public int getPeopleID()
    {
        return peopleID;
    }

    public String getAnswer()
    {
        return answer;
    }

    public byte[] getGUID()
    {
        return GUID;
    }

    public int getPacketNumber()
    {
        return packetNumber;
    }
}
